package com.baidu.shoppingmall.common.util;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class JudgePictureUploadUtils {

    @Autowired
    private FileDfsUtil fileDfsUtil;

    public String judgePictureUpload(MultipartFile[] files){
        String result = "";
        StringBuilder stringBuilder = new StringBuilder();
        try {
        	if (files!=null){

				for (MultipartFile file : files) {
					String path = fileDfsUtil.upload(file);
					if (StringUtils.isEmpty(path)){
						//图片添加失败
						return "";
					}else {
						//图片添加成功
						stringBuilder.append("http://192.168.198.131:8080/"+path+",");
					}
				}
				result=stringBuilder.toString();
			}
		} catch (Exception e) {
			e.printStackTrace();
			//服务器异常
			return  "";
		}
        return result;
    }
}
